/*
* SavingsAccount
*
* r1
*
* GNU General Public License v3.0
*/

package com.acme.bankapp.domain.bank;

import java.util.*;

public class SavingsAccount extends AbstractAccount {
	
	private Date lastDepositDate = null;
	private double interest = 0.055;
	
	public SavingsAccount(double balance) {
		super(balance);
	}
	
	public void setInterest(double interest) {
		this.interest = interest;
	}
	
	public void tryInterestAddition() {
		if(new Date().getTime() >= this.lastDepositDate.getTime() + 1000 * 60 * 60 * 24 * 30 * 6) {
			deposit(this.balance * this.interest);
		}
	}
	
	@Override
	public void deposit(double amount) {
		super.deposit(amount);
		
		this.lastDepositDate = new Date();
	}

	public void withdraw(double amount) {
		if(this.balance >= amount) {
			this.balance -= amount;
		} else {
			System.out.println("Error: You don't have that amount of money");
		}
	}
	
	public double maximumAmountToWithdraw() {
		return this.balance;
	}
	
}
